﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Agresso.Interface.Layer.Domain
{
    public class ud_voyageimp
    {
        public int recid;
        public string client;
        public string attribute_id;
        public string dim_value;
        public string description;//null
        public string rel_value;

        public DateTime voy_cpdate;
        public DateTime voy_actual_voy_start;
        public DateTime voy_actual_voy_end;
        public decimal voy_total_actual_duration;
        public decimal voy_offhire_duration;//null
        public string voy_cargo_type;//null
        public decimal voy_cargo_quantity;//null
        public string voy_fixture_number;
        public string voy_freight_rate_per_day;
        public string voy_tc_rate_per_day;
        public string voy_type_of_vc;
        public string voy_head_fixture_ref;
        public string processed_status;
        public DateTime processed_date;//null

        public string voy_actual_voy_start_time;
        public string voy_actual_voy_end_time;
        public string voy_lumpsum_freight;

        public decimal voy_cargo_quantity1 = 0;
        public string voy_charterer = "";

        public ud_voyageimp(SqlDataReader rd)
        {
            recid = rd["recid"] is DBNull ? recid : Convert.ToInt32(rd["recid"]);
            client = rd["client"] is DBNull ? client : rd["client"].ToString();
            attribute_id = rd["attribute_id"] is DBNull ? attribute_id : rd["attribute_id"].ToString();
            dim_value = rd["dim_value"] is DBNull ? dim_value : rd["dim_value"].ToString();
            description = rd["description"] is DBNull ? description : rd["description"].ToString();
            rel_value = rd["rel_value"] is DBNull ? rel_value : rd["rel_value"].ToString();

            voy_cpdate = rd["voy_cpdate"] is DBNull ? voy_cpdate : Convert.ToDateTime(rd["voy_cpdate"]);
            voy_actual_voy_start = rd["voy_actual_voy_start"] is DBNull ? voy_actual_voy_start : Convert.ToDateTime(rd["voy_actual_voy_start"]);
            voy_actual_voy_end = rd["voy_actual_voy_end"] is DBNull ? voy_actual_voy_end : Convert.ToDateTime(rd["voy_actual_voy_end"]);
            voy_total_actual_duration = rd["voy_total_actual_duration"] is DBNull ? voy_total_actual_duration : Convert.ToDecimal(rd["voy_total_actual_duration"]);
            voy_offhire_duration = rd["voy_offhire_duration"] is DBNull ? voy_offhire_duration : Convert.ToDecimal(rd["voy_offhire_duration"]);
            voy_cargo_type = rd["voy_cargo_type"] is DBNull ? voy_cargo_type : rd["voy_cargo_type"].ToString() ;
            voy_cargo_quantity = rd["voy_cargo_quantity"] is DBNull ? voy_cargo_quantity : Convert.ToDecimal(rd["voy_cargo_quantity"]);
            voy_fixture_number = rd["voy_fixture_number"] is DBNull ? voy_fixture_number : rd["voy_fixture_number"].ToString();
            voy_freight_rate_per_day = rd["voy_freight_rate_per_day"] is DBNull ? voy_freight_rate_per_day : rd["voy_freight_rate_per_day"].ToString();
            voy_tc_rate_per_day = rd["voy_tc_rate_per_day"] is DBNull ? voy_tc_rate_per_day : rd["voy_tc_rate_per_day"].ToString();
            voy_type_of_vc = rd["voy_type_of_vc"] is DBNull ? voy_type_of_vc : rd["voy_type_of_vc"].ToString();
            voy_head_fixture_ref = rd["voy_head_fixture_ref"] is DBNull ? voy_head_fixture_ref : rd["voy_head_fixture_ref"].ToString();

            processed_status = rd["processed_status"] is DBNull ? processed_status : rd["processed_status"].ToString();
            processed_date = rd["processed_date"] is DBNull ? processed_date : Convert.ToDateTime(rd["processed_date"]);

            voy_actual_voy_start_time = rd["voy_actual_voy_start_time"] is DBNull ? voy_actual_voy_start_time : rd["voy_actual_voy_start_time"].ToString();
            voy_actual_voy_end_time = rd["voy_actual_voy_end_time"] is DBNull ? voy_actual_voy_end_time : rd["voy_actual_voy_end_time"].ToString();
            voy_lumpsum_freight = rd["voy_lumpsum_freight"] is DBNull ? voy_lumpsum_freight : rd["voy_lumpsum_freight"].ToString();

            voy_cargo_quantity1 = rd["voy_cargo_quantity1"] is DBNull ? voy_cargo_quantity1 : Convert.ToDecimal(rd["voy_cargo_quantity1"]);
            voy_charterer = rd["voy_charterer"] is DBNull ? voy_charterer : rd["voy_charterer"].ToString();

        }
        public ud_voyageimp(string mclient, string dimVal, VoyageMaster vm)
        {
            recid = 0;
            client = mclient;
            attribute_id = "P8A";// carina 08-04-2013 //"PXYZ";
            dim_value = dimVal + "-V" + vm.voyage_no.ToString().PadLeft(3, '0');
            description = vm.vessel_name;
            rel_value = dimVal;
            voy_cpdate = vm.cp_date;
            voy_actual_voy_start = vm.start_ballast_date == new DateTime(1900, 1, 1) ? vm.start_voyage_delivery_date : vm.start_ballast_date;
            voy_actual_voy_end = vm.end_voyage_delivery_date;
            voy_total_actual_duration = vm.days_total_on_hire;
            voy_offhire_duration = vm.days_total_off_hire;
            voy_cargo_type = vm.commodity; // vm.commodity_type;carina 08-04-2013
            voy_cargo_quantity = vm.cargo_quantity;
            voy_fixture_number = vm.fixture_ref.Length > 12 ? vm.fixture_ref.Substring(0, 12) : vm.fixture_ref;//vm.head_fixture_number.ToString();
            voy_freight_rate_per_day = vm.Rate.ToString();//15072013 vm.Rate < 1000 ? vm.Rate.ToString() : "0";// vm.Rate.ToString();
            voy_tc_rate_per_day = vm.tce.ToString();
            voy_type_of_vc = vm.head_fixture_type;           
            voy_head_fixture_ref = vm.head_fixture_ref;
            voy_lumpsum_freight = "0";//15072013 vm.Rate >= 1000 ? vm.Rate.ToString() : "0";// vm.head_fixture_type == "VOY" || vm.head_fixture_type == "COA" ? vm.Rate.ToString() : "0";
            processed_status = "U";
            processed_date = DateTime.Now;
            voy_cargo_quantity1 = vm.cargo_quantity;
            voy_charterer = vm.charterer;
        }
    }
}
